#include "Client.h"
#include "../DataLib/ICommand.h"
#include <iostream>

using namespace std;

int main()
{
	int command;
	int size;

	byte * buffer;
	WSADATA data;
	pSocket::InitWinSock(data);
	Client client;

	try
	{
		client.Connect("127.0.0.1", 8080);
		cout << "Choose: " << endl;
		cout << "1. MOVE_MOUSE" << endl;
		cout << "2. SEND_INPUT" << endl;
		cin >> command;
		while(true)
		{
			switch(command)
			{
			case MOVE_MOUSE:
					int x;
					int y;
					Command h(0x01);
					cout << "Syntax: Enter X-Axis coordinate followed by Y-Axis coordinate." << endl;
					cin >> x >> y;
					h.AddParams(reinterpret_cast<byte*>(x) ,reinterpret_cast<byte*>(y));
					client.Send(h.Generate(), h.);
					cout << "Command sent to server." << endl;
					delete[] buffer;
					break;

			//case SEND_INPUT:
					//byte type;
					//byte key;
					//size = 3;
					//buffer = new byte[size+1];
					//cout << "Enter type(0 for a mouse action, 1 for pressing a key on the keyboard)" << endl;
					//cin >> command;
					//if(command == 0)
					//{
					//	type = 0x0;
					//	cout << "Mouse input: Enter 0 for right click, 1 for left click" << endl;
					//	cin >> command;
					//	if(!(command == 0 || command==1))
					//	{
					//		delete[] buffer;
					//		break;
					//	}
					//	key = command;
					//}
					//else if(command == 1)
					//{
					//	type = 0x1;
					//	cout << "KB input: Enter a key to press (You can enter its virtual key code)" << endl;
					//	cin >> key;
					//}
					//else
					//{
					//	delete[] buffer;
					//	break;
					//}
					//buffer[0] = size;
					//buffer[1] = SEND_INPUT;
					//buffer[2] = type;
					//buffer[3] = key;
					//client.Send(buffer, size);
					//cout << "Command sent to server." << endl;
					//delete[] buffer;
					break;

//			default:
	//				cout << "Invalid choice. Try again." << endl;
			}
			cin >> command;
		}
		pSocket::CleanWinSock();
	}
	catch(int error)
	{
		if(error == SOCKET_ERROR)
		{
			cout << "Lost connection to server." << endl;
		}
		else
		{
			cout << "Something went wrong" << endl;
		}
	}
	catch(...)
	{
		cout << "Something went wrong" << endl;
	}

}